 <?php
class PaymentType extends CActiveRecord {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function tableName() {
        return "mt_payment_type";
    }
    
    public function attributeLabels() {
        return array(
            "payment_type_name_thai" => "ชื่อการชำระเงินภาษาไทย",
            "payment_type_name_eng" => "ชื่อการชำระเงินภาษาอังกฤษ",
            "payment_type_description" => "รายละเอียดการชำระเงิน",
            "payment_type_status" => "สถานะ",
            "payment_type_create_date" => "วันที่",
            "payment_type_modified_date" => "วันที่แก้ไข",
        );
    }
    
    public function rules() {
        return array(
            array("payment_type_name_thai, payment_type_name_eng", "required",'message'=>'กรุณากรอกข้อมูลให้ครบ'),
            array("payment_type_name_thai", "length", "max" => 255),
            array("payment_type_name_eng", "length", "max" => 255),
        );
    }
    
    public function search() {
        $criteria = new CDbCriteria;
        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }
    
    public function beforeValidate() {
        if ($this->isNewRecord) {
            $this->payment_type_status = 1;
            $this->payment_type_create_date = new CDbExpression("NOW()");
        }
        else
        {
            $this->payment_type_modified_date = new CDbExpression("NOW()");
        }

        return parent::beforeValidate();
    }
    
    public static function getSexName($sex) {
        if (!empty($sex)) {
            $arr = array(
                "f" => "หญิง",
                "m" => "ขาย"
            );
            return $arr[$sex];
        }
        return "";
    }
}
?>
